﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WHM3.AdminMyInfo
{
    public partial class myInfo : System.Web.UI.Page
    {
        LinkedList<Shift> shifts;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                LoginDetails details = (LoginDetails)Session["loginDetails"];

                BL.init();
                Employee employee = BL.getEmployeeByLoginDetails(details);

                // Label IDl = (Label)FindControl("IDlabel");
                this.IDlabel.Text = employee.id;
                this.nameLabel.Text = employee.lastName + " " + employee.firstName;
                this.PositionLabel.Text = employee.Position;
                shifts = BL.getAllShiftsById(employee.id);
            }
            catch
            {

            }
        }


        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            foreach (Shift shift in shifts)
            {
                //display shift on calendar
                if (e.Day.Date.Month.ToString() == shift.getStartMonth() && e.Day.DayNumberText == shift.getStartDay() && !e.Day.IsOtherMonth)
                {
                    Label label1 = new Label();

                    label1.Text = "<br />" + shift.getStartHour() + ":" + shift.getStartMin();

                    if (shift.getEndHour() != null && shift.getEndMin() != null)
                    {
                        label1.Text += " - " + shift.getEndHour() + ":" + shift.getEndMin();
                    }

                    e.Cell.Font.Italic = true;
                    e.Cell.Font.Size = FontUnit.Small;
                    e.Cell.Controls.Add(label1);
                }

            }
            
            string onmouseoverStyle = "this.style.backgroundColor='#D4EDFF'";
            string onmouseoutStyle = "this.style.backgroundColor='@BackColor'";
            string rowBackColor = String.Empty;

            e.Cell.Attributes.Add("onmouseover", onmouseoverStyle);
            e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor));
        }

       

        protected void Selection_Change(object sender, EventArgs e)
        {
            SelectedDatesCollection theDates = Calendar1.SelectedDates;
            
            DateTime date = theDates[0];

            string shiftToChange = date.Day.ToString() + "/" + date.Month.ToString() + "/" + date.Year.ToString();
            Session["shiftToChange"] = shiftToChange;
           
            Response.Redirect("~/ShiftEdit/shiftEdit.aspx");
        }
    }
}